package com.example.yadmin.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
//API公共响应封装
@Data//lombok语法
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {//有泛型数据实体类
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success(){//无参构造
        return new Result<>(20000,"success",null);
    }
    //进行三种重载
    public static <T> Result<T> success(T data){//有参构造
        return new Result<>(20000,"success",data);
    }
    public static <T> Result<T> success(T data, String message){
        return new Result<>(20000,message,data);
    }

    public static <T> Result<T> success(String message){
        return new Result<>(20000,message,null);
    }

    public static <T> Result<T> fail(){
        return new Result<>(20001,"fail",null);
    }

    public static <T> Result<T> fail(Integer code){
        return new Result<>(code,"fail",null);
    }

    public static <T> Result<T> fail(Integer code,String message){
        return new Result<>(code,message,null);
    }

    public static <T> Result<T> fail(String message){
        return new Result<>(20001,message,null);
    }

}
